<!-- 查看，审核，价格库存页面--禹光彩--2017-7-19 15:49:40 -->
<template>
  <div>
    <div class="oh">
      <div class="fl">
        <div><span class="rightalign">产品编号：</span><span class="wd300">{{ product.productCode }}</span></div>
        <div><span style="vertical-align: top; width: 160px; text-align: right;display:inline-block">供应商产品名称：</span><span class="wd300" style="word-break:break-all;width:240px;">{{ product.supplyProductName }}</span></div>
        <div><span class="rightalign" style="vertical-align: top;line-height:0px;margin-top:30px;">来单产品名称：</span><span class="wd300" style="word-break:break-all;margin-top:20px;width:240px;vertical-align: top">{{ product. productMainTitle}}</span></div>
        <div style="margin-top:10px"><span class="rightalign">产品类型：</span><span class="wd300">{{ formatProType(product.productType) }}</span></div>
        <div><span class="rightalign">出发地：</span><span class="wd300">{{ product.dpt }}</span></div>
        <div><span class="rightalign">目的地：</span><span class="wd300">{{ product.arr }}</span></div>
      </div>
      <div class="fl" style="margin-top:20px;">
        <el-radio-group v-model="product.auditState" @change="ischange">
          <el-radio class="radio" :label="2">审核成功</el-radio>
          <el-radio class="radio" :label="3" style="margin-left:60px">审核失败</el-radio>
        </el-radio-group>
        <div style="color:#ff4949;font-size: 14px;" v-if="isAudits">请选择审核状态</div>
        <el-input v-model="product.auditResult"
          type="textarea"
          placeholder="请输入审核内容" style="margin-top:30px;width:300px;display:block">
        </el-input>
        <div style="color:#ff4949;font-size: 14px;" v-if="product.auditState === 3 && product.auditResult === ''">请填写审核内容</div>
        <el-button @click="goBack" style="margin-left:50px">返回</el-button>
        <el-button type="primary" style="margin-top:30px;margin-left:60px" @click="auditsSubmit" :loading="auditsing">提交</el-button>
      </div>
    </div>
  </div>
</template>
<script type="text/ecmascript-6">
  import {resetBreads, sessionOut} from '../../smartlight/common/js/util.js'
  export default {
    props: {
      productId: {
        type: Number
      }
    },
    data () {
      return {
        isAudits: false,
        auditsing: false,
        loginType: '',
        showPage: '0', // 显示的页签
        pageType: '',
        product: {
          id: '',
          productCode: '', // 产品编号
          productType: '', // 产品类型
          dpt: '', // 出发地
          arr: '', // 目的地
          productMainTitle: '', // 途游产品名称主标题
          supplyProductName: '', // 供应商产品名称
          productState: '', // 产品状态,true=有效,false= 无效
          auditState: -1, // 审核状态,-1=全部，0=待提交,1=审核中,2=审核通过,3=已驳回，4=已废弃
          auditResult: '' // 审核结果
        }
      }
    },
    methods: {
      // 格式化产品类型
      formatProType (val) {
        if (val === 'group') { // group=跟团游, free=自由行, themt=主题游
          return '跟团游'
        } else if (val === 'free') {
          return '自由行'
        } else if (val === 'themt') {
          return '主题游'
        }
      },
      goBack () { // 取消点击事件，返回原页面
        this.$router.push({path: '/productManageList'})
        this.$store.dispatch('updatelocationpath', '/productManageList')
        var breads = this.$store.state.breads
        breads.splice(breads.length - 1, 1)
        this.$store.dispatch('updateBreads', breads)
      },
      // 根据Id查询
      getById () {
        this.$http.post('/smartLight/web/productTour/getById.htm', {type: this.loginType, id: this.product.id}).then(response => {
          var resBody = response.body
          if (resBody.isSuccess === 0) {
            this.product = resBody.result
          } else if (resBody.isSuccess === 2) {
            sessionOut(this) // session超时处理
          } else {
            this.$message({
              showClose: true,
              message: resBody.errorMsg,
              type: 'error'
            })
          }
        })
      },
      // 审核提交
      auditsSubmit () {
        if (this.product.auditState !== 2 && this.product.auditState !== 3) {
          this.isAudits = true
          return
        } else if (this.product.auditState === 3 && this.product.auditResult === '') { // 审核失败 并且审核结果为空
          return
        }
        // 后台提交审核的结果，更新数据库
        let param = {
          type: this.loginType,
          id: this.product.id,
          auditState: this.product.auditState,
          auditResult: this.product.auditResult
        }
        this.auditsing = true
        this.$http.post('/tour/web/productTour/auditsProduct.htm', param).then(response => {
          var resBody = response.body
          if (resBody.isSuccess === 0) {
            this.product = resBody.result
            this.$message({
              showClose: true,
              message: '审核成功',
              type: 'success'
            })
            let _this = this
            setTimeout(function () {
              _this.$router.push({path: '/productManageList'})
            }, 1000)
          } else if (resBody.isSuccess === 2) {
            sessionOut(this) // session超时处理
          } else {
            this.auditsing = false
            this.$message({
              showClose: true,
              message: resBody.errorMsg,
              type: 'error'
            })
          }
        })
      },
      // 审核单选按钮change时间
      ischange (val) {
        this.isAudits = false
        this.product.auditState = val
      }
    },
    mounted () {
      resetBreads(this)
      var user = sessionStorage.getItem('user')
      if (user) {
        user = JSON.parse(user)
        this.loginType = user.type
        if (this.productId > 0) {
          this.product.id = this.productId
          this.getById()
        }
      }
    }
  }
</script>
<style lang="stylus" rel="stylesheet/stylus">
  .rightalign
    width:160px;text-align:right;display:inline-block;margin-top:20px
  .fl
    float:left;
  .oh
    overflow:hidden;
  .wd300
    width:300px;display:inline-block

</style>
